layui.use([
    'element',
    'form',
    'layer',
    'upload'
], function() {
    // $(function () {
    //     new Match();
    // });
    (function () {
        var Match = window.Match = function () {
            return new Match.prototype.init();

        };
        Match.fn = Match.prototype = {
            upFileId:null,
            urls: {
                previewUrl:CommonUtils.siteName+'images/excel.png',
                executeMatchUrl:CommonUtils.siteName+'api/project/excMatch'
            },

            init: function () {
                this.initOpt();
                this.initEvent();
                return this;
            },
            initOpt: function () {
                var that = this;
            },
            initEvent: function () {
                var that = this;

                layer.load();
                layui.upload.render({
                    elem: '.upload-prjFile' //绑定元素
                    , url: $('.upload-prjFile').attr('up-url') //上传接口
                    , field: 'prjFile' //文件域的字段名
                    , acceptMime: 'application/vnd.ms-excel' //选择文件类型
                    , exts: 'xls' //支持的图片格式
                    , multiple: true //开启多文件选择
                    , choose: function (obj) {
                        obj.preview(function (index, file, result) {
                            var upload = $('.upload-prjFile');
                            var previewUrl=upload.attr('preview-url')
                            var name = upload.attr('name');
                            var show = upload.parents('.layui-form-item').children('.upload-show');
                            show.append("<div class='upload-item'><img style='height: 64px;width: 64px;' src='"+that.urls.previewUrl+"'/>" +
                                "<input id='" + index + "' type='hidden' name='fileId'/>" +
                                "<i class='upload-item-close layui-icon layui-icon-close'></i></div>");
                        });
                    }
                    , done: function (res, index, upload) {
                        that.upFileId=res.data.id;
                        $("input[name='fileId']").val(res.data.id);
                    }
                });

                /**
                 * 开始项目匹配
                 */
                $(".ajax-match").click(function () {
                    var param={
                        upFileId:that.upFileId
                    };
                    $.get(that.urls.executeMatchUrl,param, function (result) {
                        debugger;
                        var res=result;
                    });
                });
            },
        };
        Match.fn.init.prototype = Match.fn;
    })();
});






